﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IList<BA2009.Entities.Page>>" %>
<%@ Import Namespace="MvcContrib.UI.Grid" %>
<%@ Import Namespace="MvcContrib.UI.Grid.ActionSyntax" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <link href="../../media/css/jtable.css" rel="stylesheet" type="text/css" />
    <link href="../../media/css/StyleSheet.css" rel="stylesheet" type="text/css" />
    <link href="../../media/css/jquery.cluetip.css" rel="stylesheet" type="text/css" />
    <link href="../../media/css/confirm.css" rel="stylesheet" type="text/css" />
    
    <!--Scripts-->
    <script src="../../media/js/jTable-Customize.js" type="text/javascript"></script>
    <script src="../../media/js/jquery.dimensions-1.2.js" type="text/javascript"></script>
    <script src="../../media/js/jquery.cluetip.js" type="text/javascript"></script>
    <script src="../../media/js/jquery.simplemodal.js" type="text/javascript"></script>
    
    <script type="text/javascript">
        $(document).ready(function() {

            createTable();

        }
        );
        
        
    </script>
    <script type="text/javascript">
        $(document).ready(function() {

            $(".actions").each(function() {
                var btn = $(this).find(".delete");

                $(this).find(".delete").click(function(e) {
                    e.preventDefault();
                    var msg = $(this).attr("title")
                    var selectedId = $(this).attr("id")

                    var selectedRow = $(this).parent().parent().parent();

                    confirm("Bạn có muốn xóa page " + msg + "?", function() {
                        deleteRow(selectedRow, btn, selectedId);
                    });


                });
            });
        });

        function deleteRow(row, args, id) {

            var url = "/Pages/Delete/" + id;

            $.post(url, null,
                function(data) {
                    removeRow(row, data);

                }
            , "json");

            return true;
        }

        function removeRow(row, data) {
            if (data == true) {
                row.remove();
            }
            else {
                alert("Xóa thất bại, vui lòng thử lại.");
            }
        }
        function confirm(message, callback) {
            $('#confirm').modal({
                close: false,
                overlayId: 'confirmModalOverlay',
                containerId: 'confirmModalContainer',
                onShow: function(dialog) {
                    dialog.data.find('.message').append(message);

                    // if the user clicks "yes"
                    dialog.data.find('.yes').click(function() {
                        // call the callback
                        if ($.isFunction(callback)) {
                            callback.apply();
                        }
                        // close the dialog
                        $.modal.close();
                    });
                }
            });
        }
                            
</script>

    <h2>Danh sách các trang</h2>
    
    <div id="search_container">
        <%Html.Grid(Model)
          .Columns(column =>
              {
                  column.For(c => c.PageID).Named("ID");
                  column.For(c => c.Code).Named("Mã").Action(page=>{%>
<td>
                    <a href="/BannerPositions/Index/?page=<%=page.PageID %>"><%=page.Code%></a>
                    </td>
                  
                  <%});
                  column.For(c => c.PageName).Named("Tên Trang");
                  column.For(c => c.Description).Named("Diễn Tả");
                  column.For(c => c.PageID).Named("Thao Tác").Action(page =>
                      {%>
                        <td class="actions" id="row<%= page.PageID %>">
                        <a href="/Pages/Edit/<%= page.PageID %>"> <img src="../../media/images/edit.png" style="border-width: 0px;" alt="Thay đổi" class="edit" /> </a> 
                        <a href="#"> <img src="../../media/images/delete.png" style="border-width: 0px;" id="<%=page.PageID %>" title="<%=page.Code %>"  alt="Xóa" class="delete" /> </a> 
                        </td>
                       <%}
                      );
              })
              .RowAttributes(row => new MvcContrib.Hash(id => "tablerow"+row.Item.PageID))
              .Attributes(id => "page_index_datatable")   
              .Render();
                           
                       
           %>
    </div>
    
   <!--Commented by quyenbc -->
   <%-- <table>
        <tr>
            <th class="page-td">
                ID
            </th>
            <th class="page-td">
                Tên Trang
            </th>
            <th>
                Vị trí các Banners
            </th>
            <th class="page-td">
                Diễn Tả
            </th>
            <th width="100px" class="page-td">
                Thao tác
            </th>
        </tr>
        <%foreach (var page in Model.ToList())
          {%>
            <tr>
                <td width="20px" class="page-td">
                    <%=Html.Encode(page.PageID) %>
                </td>
                <td width="150px" class="page-td">
                    <%=Html.Encode(page.PageName) %>
                </td>
                <td width="120px">
                    <%=Html.ActionLink("Tạo vị trí banner", "BannerPositionCreate", new{id= page.PageID})%>
                    <br /><br />
                    <%=Html.ActionLink("Chỉnh sửa", "BannerPositionEdit")%>
                </td>
                <td width="300px" class="page-td" align="left">
                    <%=Html.Encode(page.Description) %>
                </td>
                <td class="page-td" width="140px">
                    <a href='<%=Url.Action("Details", new { id=page.PageID})%>'><img height="30px" width="30px" src="../../Images/monitor.png" alt="View" border="0" name="View" Title="Xem Chi Tiết" /></a>
                    <a href='<%=Url.Action("Edit", new { id=page.PageID})%>'><img height="30px" width="30px" src="../../Images/kate.png" alt="Edit" border="0" name="Edit" Title="Chỉnh Sửa" /></a>
                    <a href='<%=Url.Action("Delete", new { id=page.PageID})%>'><img height="35px" width="35px" src="../../Images/x_symbol.png" alt="Delete" border="0" name="Delete" Title="Xoá Trang Này"  /></a>
                </td>
            </tr>
        <%} %>
    </table>--%>
    
</asp:Content>

